<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <script>
                function title() {
                    document.getElementById('atendimento').className='selected';
                }
                window.onload=title;
            </script>

            <style>
                .ui-panel .ui-panel-titlebar{
                    color: #0088CC;
                    background: none repeat scroll 0 0 #FFFFFF !important;
                }
            </style>


            <h:form id="diaryForm" enctype="multipart/form-data">
                <h1 class="title">
                    <a href="#" class="back" onclick="history.go(-1)"/>
                    Atendimento
                </h1>
                <p:messages autoUpdate="true" showDetail="true" id="messages" closable="true"/>
                <div class="row">
                    <div class="twelve columns">
                        <div class="container_24 clearfix ">
                            <div class="clear"/>
                            <fieldset style="margin: 0px;">
                                <legend>  <h5>
                                        <h:outputText  value="#{managerAtendimento.customer.gender eq 'MASCULINO' ?
                                                                'Sr. ':'Sra. '}#{managerAtendimento.customer.name}"/>
                                        <h:outputText  value="#{managerAtendimento.age ne '0' ? ' - ' : ''}#{managerAtendimento.age ne '0' ?
                                                                managerAtendimento.age : ''}#{managerAtendimento.age ne '0' ? ' Anos' : ''}"/>
                                        <h:outputText  value="#{managerAtendimento.operatorDiary ne null ?' - ':''}#{managerAtendimento.operatorDiary ne null ?
                                                                managerAtendimento.operatorDiary.name:''}"/>
                                    </h5></legend>

                                <p:panel id="atendimentoperfil" 
                                         style="background: none; border: none; margin: 0px;" 
                                         styleClass="container_24 clearfix">

                                    <div class="grid_5">
                                        <p:panel header="Paciente" styleClass="grid_24" style="text-align: center;">
                                            <p:graphicImage id="avatar1" styleClass="image grid_3" 
                                                            style="margin-left:1%; width: 120px;" 
                                                            alt="#{managerAtendimento.customer.annex.id}" 
                                                            title="#{managerAtendimento.customer.annex.id}"
                                                            url="#{managerAtendimento.customer.annex.id eq null ? '':'show/?annex='}#{managerAtendimento.customer.annex.id eq null ? 'assets/images/avatar.jpg': managerAtendimento.customer.annex.id}" />
                                            <div class="clear"></div>

                                            <div class="grid_24" style="text-align: left; ">

                                                <h:outputText  value="Idade:" styleClass="grid_13" style="font-weight: bold; "/>
                                                <h:outputText  value="#{managerAtendimento.age ne '0' ? ' ' : ''}
                                                               #{managerAtendimento.age ne '0' ?
                                                                 managerAtendimento.age : ''}
                                                               #{managerAtendimento.age ne '0' ? ' Anos' : ''}"
                                                               styleClass="grid_9"/>

                                                <h:outputText value="Estado Civil:" styleClass="grid_15" style="font-weight: bold;"/>
                                                <h:outputText styleClass="grid_8" value="#{managerAtendimento.customer.civilStatus.name}"/>
                                                <div class="clear"></div>
                                                <h:outputText value="Telefones:" styleClass="grid_13" style="font-weight: bold;"/>
                                                <div class="clear"></div>
                                                <h:outputText styleClass="grid_23 push_7" value="#{managerAtendimento.customer.phone}"/>
                                                <div class="clear"></div>
                                                <h:outputText styleClass="grid_23 push_7" value="#{managerAtendimento.customer.cellular}"/>
                                                <div class="clear"></div>
                                                <h:outputText value="E-mail:" styleClass="grid_13" style="font-weight: bold;"/>
                                                <h:outputText styleClass="grid_12" value="#{managerAtendimento.customer.email}"/>
                                                <div class="clear"></div>

                                                <p:button outcome="editcustomer.xhtml"
                                                          value="Atualizar Informações" icon="ui-icon-refresh"
                                                          styleClass="grid_24">
                                                    <f:param name="atendimentoprocedimento" value="true" />
                                                    <f:param name="customerEdit" value="#{managerAtendimento.customer.id}" />
                                                </p:button>
                                                <div class="clear"></div>

                                                <p:commandButton id="relPrint" rendered="#{managerAtendimento.diary.id != null}"
                                                                 value="Imprimir" immediate="true" icon="ui-icon-print" 
                                                                 update=":formDialog:fPanelImprimir"
                                                                 actionListener="#{managerAtendimento.verifyOtherDiary()}"
                                                                 oncomplete="fImprimir.show();"
                                                                 styleClass="grid_24" />




                                                <p:button icon="ui-icon-clock"
                                                          value="Editar Atendimento" outcome="createRecords"
                                                          rendered="#{managerAtendimento.diary.records ne null and managerLayout.doctorByLogin}"
                                                          styleClass="ui-priority-primary grid_24">
                                                    <f:param name="re" value="#{managerAtendimento.diary.records.id}" />
                                                    <f:param name="c" value="#{managerAtendimento.customer.id}" />
                                                    <f:param name="p" value="#{managerAtendimento.procedure.id}" />
                                                    <f:param name="d" value="#{managerAtendimento.doctor.id}" />
                                                </p:button>
                                                <p:button rendered="#{managerAtendimento.diary.diarySituation.toString() eq 'Aguardando Atendimento'}" 
                                                          icon="ui-icon-clock"
                                                          value="Iniciar Atendimento" outcome="createRecords"
                                                          disabled="#{managerAtendimento.diary.records ne null}"
                                                          styleClass="ui-priority-primary grid_24">
                                                    <f:param name="r" rendered="#{managerAtendimento.diary.retorno}" 
                                                             value="#{managerAtendimento.diary.retornoDiary.records.id}" />
                                                    <f:param name="c" value="#{managerAtendimento.customer.id}" />
                                                    <f:param name="p" value="#{managerAtendimento.procedure.id}" />
                                                    <f:param name="d" value="#{managerAtendimento.doctor.id}" />
                                                    <f:param name="dw" value="#{managerAtendimento.diary.id}" />
                                                </p:button>
                                                <p:button rendered="#{managerAtendimento.diary.diarySituation.toString() eq 'Aguardando Atendimento' or 
                                                                      managerAtendimento.diary.diarySituation.toString() eq 'Atendimento Realizado' ? 
                                                                      true:false}" 
                                                          icon="ui-icon-arrowreturnthick-1-w"
                                                          value="Retorno" outcome="atendimentoprocedimento.xhtml"
                                                          styleClass="ui-priority-primary grid_24">
                                                    <f:param name="step" value="3" />
                                                    <f:param name="retorno" value="true" />
                                                    <f:param name="diary" value="#{managerAtendimento.diary.id}" />
                                                </p:button>
                                            </div>


                                        </p:panel>
                                        <p:panel header="Informações do Atendimento" styleClass="grid_24" style="text-align: left; font-size: 10px;">
                                            <h:outputText  value="Cadastrado por:" styleClass="grid_24" 
                                                           style="font-weight: bold; "/>
                                            <h:outputText rendered="#{managerAtendimento.diary.systemUser ne null}"
                                                          value="#{managerAtendimento.diary.systemUser.name} às " />
                                            <h:outputText rendered="#{managerAtendimento.diary.systemUser ne null}" 
                                                          value="#{managerAtendimento.diary.createAt}">
                                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
                                            </h:outputText>

                                            <hr style="margin: 5px;"/>
                                            <h:outputText  value="Atualizado por:" styleClass="grid_24" 
                                                           style="font-weight: bold; "/>

                                            <h:outputText rendered="#{managerAtendimento.diary.systemUserUpdate ne null}"
                                                          value="#{managerAtendimento.diary.systemUserUpdate.name} às " />
                                            <h:outputText rendered="#{managerAtendimento.diary.systemUserUpdate ne null}" 
                                                          value="#{managerAtendimento.diary.updateAt}">
                                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
                                            </h:outputText>

                                            <hr style="margin: 5px;"/>
                                            <h:outputText  value="Pagamento recebido por:" styleClass="grid_24" 
                                                           style="font-weight: bold; "/>
                                            <h:outputText rendered="#{managerAtendimento.income.systemUser ne null}"
                                                          value="#{managerAtendimento.income.systemUser.name} às " />
                                            <h:outputText rendered="#{managerAtendimento.income.systemUser ne null}" 
                                                          value="#{managerAtendimento.income.createAt}">
                                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
                                            </h:outputText>

                                            <hr style="margin: 5px;"/>
                                            <h:outputText  value="Atendimento realizado por:" styleClass="grid_24" 
                                                           style="font-weight: bold; "/>
                                            <h:outputText rendered="#{managerAtendimento.diary.records ne null}" 
                                                          value="#{managerAtendimento.diary.records.systemUser.name}" />
                                            <h:outputText rendered="#{managerAtendimento.diary.records ne null}" 
                                                          value="#{managerAtendimento.diary.records.createAt}">
                                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
                                            </h:outputText>



                                        </p:panel>
                                    </div>

                                    <div class="grid_18">
                                        <p:tabView id="tabView" >
                                            <p:ajax event="tabChange" listener="#{managerAtendimento.onTabChange}"
                                                    immediate="true" onstart="myschedule.update();" 
                                                    process=":diaryForm:tabView:calendario" update=":diaryForm:tabView:calendario" />

                                            <p:tab id="tba1" title="Consulta/Procedimento" >
                                                <p:panel id="panelatendimento" style="background: none; border: none; margin: 0px;"
                                                         styleClass="container_24 clearfix">

                                                    <p:outputLabel for="retorno" value="Retorno:" styleClass="grid_4"
                                                                   rendered="#{managerAtendimento.diary.retorno or managerAtendimento.retorno}"/>
                                                    <p:selectBooleanCheckbox id="retorno" 
                                                                             disabled="true"
                                                                             styleClass="grid_4"
                                                                             rendered="#{managerAtendimento.diary.retorno or managerAtendimento.retorno}"
                                                                             value="#{managerAtendimento.diary.retorno or managerAtendimento.retorno}" />
                                                    <div class="clear"/>
                                                    <p:outputLabel for="operator" value="Convênio:" styleClass="grid_4"/>
                                                    <p:inputText value="#{managerAtendimento.operatorDiary.name}" 
                                                                 id="operator" readonly="true"  styleClass="grid_18" 
                                                                 disabled="#{managerAtendimento.operatorDiary.id eq null}"
                                                                 style="margin-right:0px;"/>
                                                    <p:commandButton  icon="ui-icon-plus" process="@this" immediate="true"
                                                                      rendered="#{!managerAtendimento.atendimento}"
                                                                      styleClass="ui-button-icon-only"  type="button" 
                                                                      title="Adicionar Convênio" alt="Adicionar Convênio"
                                                                      style="width: 25px; height: 28px; margin-left:0px;" 
                                                                      onclick="dlgOperatorDialog.show();"/>
                                                    <p:commandButton  icon="ui-icon-trash" 
                                                                      rendered="#{managerAtendimento.operatorDiary.id ne null and !managerAtendimento.atendimento? true:false}"
                                                                      title="Remover Convênio" alt="Remover Convênio"
                                                                      update="@this, :diaryForm:tabView:panelatendimento, :diaryForm:tabView:fPanel"  
                                                                      process="@this" styleClass="ui-button-icon-only" 
                                                                      style="width: 25px; height: 28px; margin-left:30px;" 
                                                                      immediate="false" actionListener="#{managerAtendimento.clearOperator()}" />


                                                    <div class="clear"></div>
                                                    <p:outputLabel for="procedure" value="Procedimento:" styleClass="grid_4"/>  
                                                    <p:inputText value="#{managerAtendimento.procedure.name}" 
                                                                 disabled="#{managerAtendimento.procedure.id eq null}"
                                                                 id="procedure" readonly="true"  styleClass="grid_18" style="margin-right:0px;"/>

                                                    <p:commandButton  icon="ui-icon-plus" process="@this" immediate="true"
                                                                      styleClass="ui-button-icon-only"  type="button" 
                                                                      rendered="#{!managerAtendimento.atendimento}"
                                                                      style="width: 25px; height: 28px; margin-left:0px;" 
                                                                      title="Adicionar Procedimento" alt="Adicionar Procedimento"
                                                                      onclick="dlgProcedureDialog.show();"/>

                                                    <p:commandButton  icon="ui-icon-trash"
                                                                      rendered="#{managerAtendimento.procedure.id ne null and !managerAtendimento.atendimento ? true:false}"
                                                                      title="Remover Procedimento" alt="Remover Procedimento"
                                                                      update="@this, :diaryForm:tabView:panelatendimento, :diaryForm:tabView:fPanel" 
                                                                      process="@this" styleClass="ui-button-icon-only grid_3" 
                                                                      style="width: 25px; height: 28px; margin-left:30px;" 
                                                                      immediate="false" actionListener="#{managerAtendimento.clearProcedure()}" />


                                                    <div class="clear"/>



                                                    <div class="clear"/>
                                                    <p:outputLabel for="doctor" value="Médico Responsável:" styleClass="grid_6" 
                                                                   style="margin-left:-43px;" />  
                                                    <p:inputText value="#{managerAtendimento.doctor.name}" 
                                                                 disabled="#{managerAtendimento.doctor.id eq null}"
                                                                 id="doctor" readonly="true"  styleClass="grid_18" style="margin-right:0px;"/>

                                                    <p:commandButton  icon="ui-icon-plus" type="button"
                                                                      styleClass="ui-button-icon-only" 
                                                                      rendered="#{!managerAtendimento.atendimento}"
                                                                      style="width: 25px; height: 28px; margin-left:0px;" 
                                                                      title="Adicionar Médico Responsável" alt="Adicionar Médico Responsável"
                                                                      onclick="dlgDoctorDialog.show()"/>

                                                    <p:commandButton  icon="ui-icon-trash"
                                                                      rendered="#{managerAtendimento.doctor.id ne null and !managerAtendimento.atendimento ? true:false}"
                                                                      title="Remover Médico Responsável" alt="Remover Médico Responsável"
                                                                      update="@this, :diaryForm:tabView:panelatendimento" 
                                                                      process="@this"   styleClass="ui-button-icon-only" 
                                                                      style="width: 25px; height: 28px; margin-left:30px;"
                                                                      immediate="false" actionListener="#{managerAtendimento.clearDoctor()}" />



                                                    <div class="clear"/>
                                                    <p:outputLabel for="doctorRequest" value="Médico Solicitante:" styleClass="grid_6" style="margin-left:-43px;"/>  
                                                    <p:inputText value="#{managerAtendimento.doctorRequest.name}" 
                                                                 disabled="#{managerAtendimento.doctorRequest.id eq null }"
                                                                 id="doctorRequest" readonly="true" 
                                                                 styleClass="grid_18" style="margin-right:0px;"/>

                                                    <p:commandButton  icon="ui-icon-plus" type="button"
                                                                      styleClass="ui-button-icon-only" 
                                                                      rendered="#{!managerAtendimento.atendimento}"
                                                                      style="width: 25px; height: 28px; margin-left:0px;"
                                                                      title="Adicionar Médico Solicitante" alt="Adicionar Médico Solicitante"
                                                                      onclick="dlgDoctorRequestDialog.show()"/>

                                                    <p:commandButton  icon="ui-icon-trash"
                                                                      rendered="#{managerAtendimento.doctorRequest.id ne null and !managerAtendimento.atendimento? true:false}"
                                                                      title="Remover Médico Solicitante" alt="Remover Médico Solicitante"
                                                                      update="@this, :diaryForm:tabView:panelatendimento," 
                                                                      process="@this"   styleClass="ui-button-icon-only" 
                                                                      style="width: 25px; height: 28px; margin-left:30px;"
                                                                      immediate="false" actionListener="#{managerAtendimento.clearDoctorRequest()}" />
                                                </p:panel>
                                                <p:panel id="panelhorario" style="background: none; border: none; margin: 0px;"
                                                         styleClass="container_24 clearfix">

                                                    <h5>Horário</h5>
                                                    <hr style="margin-top: 0px;"/>
                                                    <p:outputLabel for="em" value="Em: *" styleClass="grid_4"/>  
                                                    <p:calendar id="em" value="#{managerAtendimento.diary.startTime}" 
                                                                readonlyInput="#{managerAtendimento.atendimento}" locale="pt"
                                                                showOn="#{managerAtendimento.atendimento ? '':'button'}" styleClass="grid_7"
                                                                pattern="dd/MM/yyyy"
                                                                >  
                                                        <p:ajax event="dateSelect" listener="#{managerAtendimento.onDateSelect}" 
                                                                update=":diaryForm:tabView:to, :diaryForm:tabView:from" />
                                                        <p:ajax event="blur" listener="#{managerAtendimento.onDateSelect(null)}" 
                                                                update=":diaryForm:tabView:to, :diaryForm:tabView:from" />
                                                    </p:calendar>

                                                    <div class="clear"/>
                                                    <p:outputLabel for="from" value="De:" styleClass="grid_4"/>  
                                                    <p:calendar id="from" value="#{managerAtendimento.from}" 
                                                                readonlyInput="#{managerAtendimento.atendimento}" locale="pt"
                                                                showOn="#{managerAtendimento.atendimento ? '':'button'}" 
                                                                styleClass="grid_7" pattern="HH:mm"
                                                                timeOnly="true"
                                                                required="true"> 
                                                        <p:ajax event="dateSelect" listener="#{managerAtendimento.onDateSelectFrom}" 
                                                                update=":diaryForm:tabView:to, :diaryForm:tabView:em" />
                                                        <p:ajax event="blur" listener="#{managerAtendimento.onDateSelectFrom(null)}" 
                                                                update=":diaryForm:tabView:to, :diaryForm:tabView:em" />
                                                    </p:calendar>
                                                    <p:outputLabel for="to" value="Até:" styleClass="grid_4"/>  
                                                    <p:calendar id="to" value="#{managerAtendimento.diary.endTime}" 
                                                                locale="pt"
                                                                readonlyInput="#{managerAtendimento.atendimento}"
                                                                showOn="#{managerAtendimento.atendimento ? '':'button'}"
                                                                styleClass="grid_7" style="width: 29.767%;" pattern="HH:mm" 
                                                                required="true" timeOnly="true"/>  

                                                    <div class="clear"></div>
                                                    <p:outputLabel for="obs" value="Observações:" styleClass="grid_4"/>  
                                                    <p:inputTextarea autoResize="false" id="obs" 
                                                                     disabled="#{managerAtendimento.atendimento}"
                                                                     value="#{managerAtendimento.diary.observation}" 
                                                                     styleClass="grid_19"/> 
                                                    <div class="clear"></div>

                                                    <p:outputLabel for="selectSituacao" value="Situação:" styleClass="grid_4"/>
                                                    <div class="grid_19">
                                                        <p:selectOneMenu id="selectSituacao" style="width: 103%;" 
                                                                         disabled="#{managerAtendimento.atendimento}"
                                                                         value="#{managerAtendimento.diary.diarySituation}" >   
                                                            <f:selectItem itemLabel="" itemValue="" />  
                                                            <f:selectItems value="#{managerAtendimento.selectTypeDiary()}" />
                                                            <p:ajax update="@this, :diaryForm:tabView:fPanel" 
                                                                    process="@this" />
                                                        </p:selectOneMenu> 
                                                    </div>

                                                </p:panel>
                                                <p:panel id="fPanel" style="background: none; border: none; margin: 0px; 
                                                         display: #{managerAtendimento.retorno or managerAtendimento.diary.retorno ? 'none':'block'}"
                                                         styleClass="container_24 clearfix" >

                                                    <h5>Forma de Pagamento</h5>
                                                    <hr style="margin-top: 0px;"/>

                                                    <p:outputLabel value="Forma de Pagamento:" styleClass="grid_6" style="margin-left: -18px;"/> 
                                                    <div class="grid_16">
                                                        <p:selectOneMenu disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}" 
                                                                         style="width: 108%;" panelStyle="width:150px;" 
                                                                         value="#{managerAtendimento.income.paymentType}" >   
                                                            <f:selectItems value="#{managerAtendimento.selectPaymentType()}" />
                                                            <p:ajax update=":diaryForm:tabView:fPanel" />
                                                        </p:selectOneMenu>
                                                    </div>
                                                    <div class="clear"/>
                                                    <p:outputLabel for="famount" value="Valor:" styleClass="grid_5"/> 

                                                    <p:inputText id="famount" styleClass="grid_17" 
                                                                 disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}"
                                                                 value="#{managerAtendimento.income.amount}"
                                                                 onkeypress="jQuery(this).autoNumeric({aSign:'R$ ', aSep: '.', aDec: ','} );">
                                                        <f:convertNumber type="currency" locale="pt,BR"/>
                                                        <p:ajax event="blur" update="@this, ftotalamount, famountpaid" 
                                                                listener="#{managerAtendimento.calcDiscount()}"/>
                                                    </p:inputText>

                                                    <p:watermark value="R$" for="fdiscount"  />
                                                    <p:watermark value="%" for="fdiscountpercent" />

                                                    <p:outputLabel for="fdiscount" value="Desconto:" styleClass="grid_5"/>  
                                                    <p:inputText id="fdiscount" styleClass="grid_8" 
                                                                 value="#{managerAtendimento.income.discount}"
                                                                 disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}"
                                                                 onkeypress="jQuery(this).autoNumeric({aSign:'R$ ',aSep: '.', aDec: ','} );">
                                                        <f:convertNumber type="currency" locale="pt,BR"/>
                                                        <p:ajax event="blur" update="@this, ftotalamount, famountpaid" 
                                                                listener="#{managerAtendimento.calcDiscount()}"/>
                                                    </p:inputText>

                                                    <p:inputText styleClass="grid_9" 
                                                                 id="fdiscountpercent"
                                                                 style="width: 34.1%"
                                                                 disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}"
                                                                 onkeypress="jQuery(this).autoNumeric({pSign: 's',aSign: '%', aSep: '.', aDec: ','} );"
                                                                 value="#{managerAtendimento.discount}"  >
                                                        <f:convertNumber type="percent"  locale="pt,BR"  />
                                                        <p:ajax event="blur" update="@this, ftotalamount, famountpaid, fdiscount" 
                                                                listener="#{managerAtendimento.calcDiscountPorce()}"/>
                                                    </p:inputText>

                                                    <div class="clear"/>

                                                    <p:watermark value="Dinheiro" for="amountmoney"  />
                                                    <p:watermark value="Cartão" for="amountcard" />

                                                    <p:outputLabel id="labelAmountMoney"  for="amountmoney" 
                                                                   value="Valor Dinheiro:" styleClass="grid_5" 
                                                                   style="display: #{managerAtendimento.income.paymentType eq 'MONEY_CARD' ? 'block':'none'}"/>  
                                                    <p:inputText  style="display: #{managerAtendimento.income.paymentType eq 'MONEY_CARD' ? 'block':'none'}" 
                                                                  id="amountmoney" styleClass="grid_6" 
                                                                  disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}"
                                                                  value="#{managerAtendimento.income.amountMoney}"
                                                                  onkeypress="jQuery(this).autoNumeric({aSign:'R$ ',aSep: '.', aDec: ','} );">
                                                        <f:convertNumber type="currency" locale="pt,BR"/>
                                                    </p:inputText>

                                                    <p:outputLabel id="labelAmountCard"  for="amountcard" 
                                                                   value="Valor Cartão:" styleClass="grid_4" 
                                                                   style="display: #{managerAtendimento.income.paymentType eq 'MONEY_CARD' ? 'block':'none'}"/>  


                                                    <p:inputText  
                                                        style="display: #{managerAtendimento.income.paymentType eq 'MONEY_CARD' ? 'block':'none'}; width: 26%;" 
                                                        id="amountcard" styleClass="grid_6" 
                                                        disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}"
                                                        value="#{managerAtendimento.income.amountCard}"
                                                        onkeypress="jQuery(this).autoNumeric({aSign:'R$ ',aSep: '.', aDec: ','} );">
                                                        <f:convertNumber type="currency" locale="pt,BR"/>
                                                    </p:inputText>

                                                    <div class="clear"/>

                                                    <p:outputLabel for="ftotalamount" value="Valor Total:" styleClass="grid_5"/>  
                                                    <p:inputText id="ftotalamount" styleClass="grid_17"  readonly="true" 
                                                                 disabled="true"
                                                                 value="#{managerAtendimento.income.totalAmount}"
                                                                 onkeypress="jQuery(this).autoNumeric({aSep: '.', aDec: ','} );">
                                                        <f:convertNumber pattern="#,###,##0.00"/>
                                                    </p:inputText>

                                                    <p:outputLabel for="famountpaid" value="Valor Pago:" styleClass="grid_5"/>  
                                                    <p:inputText id="famountpaid" styleClass="grid_8" 
                                                                 value="#{managerAtendimento.income.amountPaid}"
                                                                 disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}"
                                                                 onkeypress="jQuery(this).autoNumeric({aSign:'R$ ', aSep: '.', aDec: ','} );">
                                                        <f:convertNumber type="currency" locale="pt,BR"/>
                                                    </p:inputText>


                                                    <p:outputLabel for="dateincome" value="Em:" styleClass="grid_2" style="width: 5%;"/>  
                                                    <p:calendar id="dateincome" value="#{managerAtendimento.income.createAt}" 
                                                                disabled="#{managerAtendimento.diary.diarySituation ne 'CALL_WAITING' or managerAtendimento.atendimento}"
                                                                showOn="button" styleClass="grid_7" pattern="dd/MM/yyyy HH:mm"/>  

                                                    <div class="clear"/>



                                                </p:panel>
                                                <p:panel id="btnPanel" 
                                                         style="background: none; border: none; margin: 0px; "
                                                         styleClass="container_24 clearfix" >
                                                    <div class="buttonAction">
                                                        <p:commandButton id="addButton" 
                                                                         value="Salvar" 
                                                                         process="@form" update="@form"
                                                                         actionListener="#{managerAtendimento.salvar()}"
                                                                         styleClass="ui-priority-primary"
                                                                         icon="ui-icon-disk"/>  
                                                        <p:button id="cancelButton" 
                                                                  value="Cancelar" 
                                                                  outcome="indexagenda.xhtml"
                                                                  icon="ui-icon-close"/>  
                                                    </div>
                                                </p:panel>
                                            </p:tab>
                                            <p:tab id="tba2" title="Calendário" >
                                                <p:schedule  id="schedule" locale="pt" slotMinutes="15" 
                                                             maxTime="21" minTime="6" 
                                                             view="agendaDay"  value="#{managerAtendimento.eventModel}"
                                                             widgetVar="myschedule">  
                                                </p:schedule>  
                                                <br/>
                                                <br/>
                                                <p:outputLabel id="calendario" />
                                                <div class="grid_19">
                                                    <h5>Legenda</h5>
                                                    <div class="agendado grid_2"
                                                         style="height: 25px;">
                                                    </div>
                                                    <div class="grid_10">
                                                        Agendado
                                                    </div>
                                                    <div class="clear"/>

                                                    <div class="confirmado fc-event-skin grid_2"
                                                         style="height: 25px;">
                                                    </div>
                                                    <div class="grid_10">
                                                        Agendamento Confirmado
                                                    </div>
                                                    <div class="clear"/>
                                                    <div class="cancelado fc-event-skin grid_2"
                                                         style="height: 25px;">
                                                    </div>
                                                    <div class="grid_10">
                                                        Cancelado
                                                    </div>
                                                    <div class="clear"/>
                                                    <div class="aguardando_atendimento fc-event-skin grid_2"
                                                         style="height: 25px;">
                                                    </div>
                                                    <div class="grid_10">
                                                        Aguardando Atendimento
                                                    </div>
                                                    <div class="clear"/>
                                                    <div class="atendimento_realizado fc-event-skin grid_2"
                                                         style="height: 25px;">
                                                    </div>
                                                    <div class="grid_10">
                                                        Atendimento Realizado
                                                    </div>
                                                    <div class="clear"/>
                                                </div>
                                            </p:tab>
                                            <p:tab id="tba3" rendered="#{managerAtendimento.atendimento}" title="Atividades Recentes" >
                                                <div class="ui-messages ui-widget" style="display: #{managerAtendimento.verificaCadastroIncompleto() ? 'block':'none'}">
                                                    <div class="ui-messages-error ui-corner-all">
                                                        <span class="ui-messages-error-icon"/>
                                                        <span class="ui-messages-error-summary">Cadastro Incompleto</span>
                                                    </div>
                                                </div>
                                                <div class="ui-messages ui-widget" style="display: #{managerAtendimento.msg ne null ? 'block':'none'}">
                                                    <div class="ui-messages-warn ui-corner-all">
                                                        <span class="ui-messages-warn-icon"/>
                                                        <ul>                                                            
                                                            <h:outputText value="#{managerAtendimento.msg}" escape="false"/>
                                                        </ul>
                                                    </div>
                                                </div>
                                                <div class="container_24 clearfix">
                                                    <p:dataTable id="searchDiary" styleClass="grid_24" var="sd" 
                                                                 rowIndexVar="ddt" emptyMessage="Nenhum Agendamento Realizado"
                                                                 paginator="true" rows="10" paginatorPosition="bottom"
                                                                 value="#{managerAtendimento.diarysRecents}"  >

                                                        <f:facet name="header">
                                                            Agendamentos (#{managerAtendimento.diarysRecents.size()})
                                                        </f:facet>

                                                        <p:column headerText="Ação" style="white-space: pre-wrap;" width="25">  
                                                            <p:button icon="ui-icon-search" outcome="atendimentoprocedimento.xhtml" 
                                                                      style="width: 25px; position: relative">
                                                                <f:param name="step" value="3"  />
                                                                <f:param name="diary" value="#{sd.id}" />
                                                            </p:button>

                                                        </p:column>
                                                        <p:column headerText="Data" style="white-space: pre-wrap;" width="75">  
                                                            <h:outputText value="#{sd.startTime}" >  
                                                                <f:convertDateTime pattern="dd/MM/yyy HH:mm:ss "  locale="pt"/>
                                                            </h:outputText>
                                                        </p:column>

                                                        <p:column headerText="Status" style="white-space: pre-wrap;" width="120">  
                                                            <h:outputText value="#{sd.diarySituation.toString()}" />  
                                                        </p:column>

                                                        <p:column headerText="Médico">  
                                                            <h:outputText value="#{sd.doctor.name}" />  
                                                        </p:column>

                                                        <p:column headerText="Procedimento">  
                                                            <h:outputText value="#{sd.procedure.name}" />  
                                                        </p:column>

                                                    </p:dataTable>
                                                </div>
                                            </p:tab>
                                            <p:tab id="tba4" rendered="#{managerLayout.doctorByLogin}" title="Histórico Clínico">

                                                
                                                <p:commandButton id="chartBtn" value="Filtros"
                                                                 icon="ui-icon-search" type="button" styleClass="right" />
                                                <p:overlayPanel for="chartBtn" style="width: 200px;">

                                                    <p:panel id="filtroprontuario" styleClass="clearfix grid_24">
                                                        <h:outputText value="Todos: " styleClass="grid_20"/>
                                                        <p:selectBooleanCheckbox value="#{managerAtendimento.showAll}">
                                                            <p:ajax update=":diaryForm:tabView:filtroprontuario"
                                                                    listener="#{managerAtendimento.todosFiltros}" />
                                                        </p:selectBooleanCheckbox>
                                                        <div class="clear"/>
                                                        <h:outputText value="Anamnese: " styleClass="grid_20"/>
                                                        <p:selectBooleanCheckbox  value="#{managerAtendimento.showAnamnese}" styleClass="grid_4">
                                                            <p:ajax update=":diaryForm:tabView:filtroprontuario"
                                                                    listener="#{managerAtendimento.disableShowAll}" />
                                                        </p:selectBooleanCheckbox>
                                                        <div class="clear"/>
                                                        <h:outputText value="Exame Fisico: " styleClass="grid_20"/>
                                                        <p:selectBooleanCheckbox value="#{managerAtendimento.showExameFisico}" styleClass="grid_4">
                                                            <p:ajax update=":diaryForm:tabView:filtroprontuario"
                                                                    listener="#{managerAtendimento.disableShowAll}" />
                                                        </p:selectBooleanCheckbox>
                                                        <div class="clear"/>
                                                        <h:outputText value="Diagnóstico: " styleClass="grid_20"/>
                                                        <p:selectBooleanCheckbox value="#{managerAtendimento.showDiagnostico}" styleClass="grid_4">
                                                            <p:ajax update=":diaryForm:tabView:filtroprontuario"
                                                                    listener="#{managerAtendimento.disableShowAll}" />
                                                        </p:selectBooleanCheckbox>
                                                        <div class="clear"/>
                                                        <h:outputText value="Receituário: " styleClass="grid_20"/>
                                                        <p:selectBooleanCheckbox value="#{managerAtendimento.showReceituario}" styleClass="grid_4">
                                                            <p:ajax update=":diaryForm:tabView:filtroprontuario"
                                                                    listener="#{managerAtendimento.disableShowAll}" />
                                                        </p:selectBooleanCheckbox>
                                                        <div class="clear"/>
                                                        <h:outputText value="Evolução/Retorno: " styleClass="grid_20"/>
                                                        <p:selectBooleanCheckbox value="#{managerAtendimento.showEvolucao}" styleClass="grid_4">
                                                            <p:ajax update=":diaryForm:tabView:filtroprontuario"
                                                                    listener="#{managerAtendimento.disableShowAll}" />
                                                        </p:selectBooleanCheckbox>
                                                        <div class="clear"/>
                                                        <h:outputText value="Anexos: " styleClass="grid_20"/>
                                                        <p:selectBooleanCheckbox value="#{managerAtendimento.showAnexos}" styleClass="grid_4">
                                                            <p:ajax update=":diaryForm:tabView:filtroprontuario"
                                                                    listener="#{managerAtendimento.disableShowAll}" />
                                                        </p:selectBooleanCheckbox>

                                                        <p:commandButton value="Filtrar"
                                                                         icon="ui-icon-search" 
                                                                         update="@this, :diaryForm:tabView:historioclinico"
                                                                         process="@this, :diaryForm:tabView:filtroprontuario"
                                                                         styleClass="grid_24" />
                                                    </p:panel>
                                                </p:overlayPanel>
                                                <div class="clear"/>

                                                <h:outputLabel value="Não há registro clínico"
                                                               styleClass="grid_7"
                                                               rendered="#{empty managerAtendimento.recordses}"/>


                                                <p:panel id="historioclinico" style="border:0px solid #fff; padding: 0px;">
                                                    
                                                    <ui:repeat value="#{managerAtendimento.recordses}" var="r">
                                                        #{managerAtendimento.diaryPorRecord(r.id)}
                                                        <div class="container_24 clearfix">
                                                            <div class="grid_3">
                                                                <p class="date">
                                                                    <a href="#">
                                                                        <h:outputText value="#{r.createAt}">
                                                                            <f:convertDateTime pattern="MMMMM" />
                                                                        </h:outputText>
                                                                        <b>
                                                                            <h:outputText value="#{r.createAt}">
                                                                                <f:convertDateTime pattern="dd"/>
                                                                            </h:outputText>

                                                                        </b>
                                                                        <span>
                                                                            <h:outputText value="#{r.createAt}">
                                                                                <f:convertDateTime pattern="yyyy"/>
                                                                            </h:outputText>
                                                                        </span>
                                                                    </a>
                                                                </p>
                                                            </div>
                                                            <p:panel style="background: none; margin:none;" 
                                                                     styleClass="grid_20" 
                                                                     collapsed="#{managerAtendimento.collapsed}"  toggleable="true" >

                                                                <f:facet name="header">
                                                                    <div class="grid_22 clearfix">

                                                                        <div class="grid_18">
                                                                            <h:outputText value="#{r.procedure.typeProcedure.name}:" styleClass="grid_5"/>
                                                                            <h:outputText value="#{r.procedure.typeProcedure.name} #{r.procedure.name}" 
                                                                                          styleClass="grid_19"/>
                                                                            <div class="clear"/>
                                                                            <h:outputText value="Médico:" styleClass="grid_5"/>
                                                                            <h:outputText value="#{r.doctor.name}" styleClass="grid_13"/>
                                                                            <div class="clear"/>
                                                                            <h:outputText value="Médico Solicitante:" styleClass="grid_10" rendered="false"/>
                                                                            <h:outputLabel value="#{managerAtendimento.diaryrecord ne null ? managerAtendimento.diaryrecord.doctorRequest.name:' - '}" 
                                                                                          styleClass="grid_13"  rendered="false"/>
                                                                            <div class="clear"/>
                                                                            <h:outputText value="Convênio:" styleClass="grid_5"  rendered="false"/>
                                                                            <h:outputText value="#{managerAtendimento.diaryrecord ne null ? managerAtendimento.diaryrecord.operator.name :' - '}" 
                                                                                          styleClass="grid_13"  rendered="false"/>
                                                                        </div>
                                                                        <p:button icon="ui-icon-arrowreturnthick-1-w" 
                                                                                  value="Retorno" outcome="createRecords"
                                                                                  rendered="true"
                                                                                  styleClass="grid_5">
                                                                            <f:param name="c" value="#{r.customer.id}" />
                                                                            <f:param name="r" value="#{r.id}" />
                                                                            <f:param name="p" value="#{r.procedure eq null ? null : r.procedure.id}" />
                                                                            <f:param name="d" value="#{r.doctor eq null ? null : r.doctor.id}" />
                                                                        </p:button>
                                                                    </div>
                                                                </f:facet>

                                                                <div class="grid_20" >
                                                                    <div style="display: #{managerAtendimento.showAnamnese ? 'block':'none'}">
                                                                        <h4 style="color: #5593CA;">Anamnese</h4>

                                                                        <ui:repeat value="#{r.anamneses}" var="ra">
                                                                            <p:outputLabel value="Queixa Principal#{ra.id}" styleClass="grid_5"/>
                                                                            <p:inputText styleClass="grid_18" readonly="true" value="#{ra.chiefComplaint}"/>
                                                                            <div class="clear"/>
                                                                            <p:outputLabel value="História" styleClass="grid_5"/>
                                                                            <div class="grid_18">
                                                                                <p:inputTextarea readonly="true" value="#{ra.descr}"/>
                                                                            </div>
                                                                        </ui:repeat>
                                                                        <p:outputLabel value="Queixa Principal" styleClass="grid_5" rendered="#{empty r.anamneses}"/>
                                                                        <p:inputText styleClass="grid_18" readonly="true" rendered="#{empty r.anamneses}"/>
                                                                        <div class="clear"/>
                                                                        <p:outputLabel value="História" styleClass="grid_5" rendered="#{empty r.anamneses}"/>
                                                                        <div class="grid_18">
                                                                            <p:inputTextarea readonly="true" rendered="#{empty r.anamneses}"/>
                                                                        </div>

                                                                        <div class="clear"/>
                                                                        <hr/>
                                                                    </div>
                                                                    <div style="display: #{managerAtendimento.showExameFisico ? 'block':'none'}">
                                                                        <h4 style="color: #5593CA;">Exame Físico</h4>

                                                                        <div class="clear"/>
                                                                        <p:outputLabel value="Altura" styleClass="grid_5"/>
                                                                        <p:inputText styleClass="grid_4" readonly="true" value="#{r.physicalExamination.height}"/>
                                                                        <p:outputLabel value="m" styleClass="grid_1"/>
                                                                        <p:outputLabel value="Peso" styleClass="grid_5"/>
                                                                        <p:inputText styleClass="grid_4" readonly="true" value="#{r.physicalExamination.weight}"/>
                                                                        <p:outputLabel value="kg" styleClass="grid_1"/>
                                                                        <div class="clear"/>
                                                                        <p:outputLabel value="Batimento Cardíaco" styleClass="grid_5"/>
                                                                        <p:inputText styleClass="grid_4" readonly="true" value="#{r.physicalExamination.heartRate}"/>
                                                                        <p:outputLabel value="bpm" styleClass="grid_1"/>
                                                                        <div class="clear"/>
                                                                        <p:outputLabel value="Pressão arterial sistólica" styleClass="grid_5"/>
                                                                        <p:inputText styleClass="grid_4" readonly="true" value="#{r.physicalExamination.systolicPressure}"/>
                                                                        <p:outputLabel value="mmHg" styleClass="grid_1"/>
                                                                        <p:outputLabel value="Pressão arterial Diastólica" styleClass="grid_5"/>
                                                                        <p:inputText styleClass="grid_4" readonly="true" value="#{r.physicalExamination.diastolicPressure}"/>
                                                                        <p:outputLabel value="mmHg" styleClass="grid_1"/>
                                                                        <div class="clear"/>
                                                                        <p:outputLabel value="Observações" styleClass="grid_5"/>
                                                                        <div class="grid_19">
                                                                            <p:inputTextarea readonly="true" value="#{r.physicalExamination.descr}"/>
                                                                        </div>
                                                                        <div class="clear"/>
                                                                        <hr/>
                                                                    </div>
                                                                    <div style="display: #{managerAtendimento.showDiagnostico ? 'block':'none'}">
                                                                        <h4 style="color: #5593CA;">Diagnóstico</h4>

                                                                        <p:outputLabel value="Diagnóstico" styleClass="grid_5"/>
                                                                        <p:inputText styleClass="grid_18" readonly="true" value="#{r.diagnostic.cid}"/>
                                                                        <div class="clear"/>
                                                                        <p:outputLabel value="Conduta" styleClass="grid_5"/>
                                                                        <div class="grid_18">
                                                                            <p:inputTextarea readonly="true" value="#{r.diagnostic.descr}"/>
                                                                        </div>
                                                                        <div class="clear"/>
                                                                        <hr/>
                                                                    </div>
                                                                    <div style="display: #{managerAtendimento.showReceituario ? 'block':'none'}">
                                                                        <h4 style="color: #5593CA;">Receituário</h4>
                                                                        <p:outputLabel value="Descrição" styleClass="grid_5"/>
                                                                        <div class="grid_18">
                                                                            <p:inputTextarea readonly="true" value="#{r.prescription}"/>
                                                                        </div>
                                                                        <div class="clear"/>
                                                                        <hr/>
                                                                    </div>
                                                                    <div style="display: #{managerAtendimento.showEvolucao ? 'block':'none'}">
                                                                        <h4 style="color: #5593CA;">Evolução/Retorno</h4>


                                                                        <ui:repeat value="#{r.evolutions}" var="ev">

                                                                            <div class="grid_6">
                                                                                <p class="date">
                                                                                    <a href="#">
                                                                                        <h:outputText value="#{ev.dateEvolution}">
                                                                                            <f:convertDateTime pattern="MMMMM" />
                                                                                        </h:outputText>
                                                                                        <b>
                                                                                            <h:outputText value="#{ev.dateEvolution}">
                                                                                                <f:convertDateTime pattern="dd"/>
                                                                                            </h:outputText>

                                                                                        </b>
                                                                                        <span>
                                                                                            <h:outputText value="#{ev.dateEvolution}">
                                                                                                <f:convertDateTime pattern="yyyy"/>
                                                                                            </h:outputText>
                                                                                        </span>
                                                                                    </a>
                                                                                </p>
                                                                            </div>
                                                                            <div class="grid_18">
                                                                                <p:outputLabel value="Data:" styleClass="grid_4" rendered="false"/>
                                                                                <p:calendar showOn="button" styleClass="grid_19" 
                                                                                            value="#{ev.dateEvolution}" rendered="false"
                                                                                            pattern="dd/MM/yyyy" required="true"/>
                                                                                <div class="clear"></div>
                                                                                <p:outputLabel value="Descrição" styleClass="grid_4"/>
                                                                                <div class="clear"></div>
                                                                                <div class="grid_23">
                                                                                    <p:inputTextarea readonly="true" value="#{ev.descr}"/>
                                                                                </div> 
                                                                                <div class="clear"></div>
                                                                            </div>
                                                                            <div class="clear"/>
                                                                        </ui:repeat>


                                                                        <div class="clear"/>
                                                                        <hr/>
                                                                    </div>
                                                                    <div style="display: #{managerAtendimento.showAnexos ? 'block':'none'}">
                                                                        <h4 style="color: #5593CA;">Anexos</h4>

                                                                        <div class="container_24 clearfix">
                                                                            <ui:repeat  value="#{r.annexs}" var="a">
                                                                                <div class="grid_5">
                                                                                    <h:outputLink  
                                                                                        value="#{a.type ne 'application/pdf' ? 'viewImage.xhtml':'show'}" 
                                                                                        title="#{a.description}"  target="_blank" >

                                                                                        <div style="text-align: center; width: 20%;" class="grid_4">

                                                                                            <p:graphicImage styleClass="image grid_3" rendered="#{a.type ne 'application/pdf'}"
                                                                                                            style="margin-left:1%; width: 100px;"
                                                                                                            url="show/?annex=#{a.id}" />

                                                                                            <p:outputLabel  value="#{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                                                                     a.description.replace('.png','').replace(' ','_')}" 
                                                                                                            style="margin-left:1%; width: 100px;" rendered="#{a.type ne 'application/pdf'}"/>

                                                                                            <p:graphicImage styleClass="image grid_3" rendered="#{a.type eq 'application/pdf'}"
                                                                                                            style="margin-left:1%; width: 100px;" 
                                                                                                            url="assets/images/pdf.jpeg" />


                                                                                            <p:outputLabel  value="#{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                                                                     a.description.replace('.pdf','').replace(' ','_')}" 
                                                                                                            style="margin-left:1%; width: 100px;" rendered="#{a.type eq 'application/pdf'}"/>


                                                                                        </div>
                                                                                        <f:param name="annex" value="#{a.id}"/>
                                                                                    </h:outputLink>
                                                                                </div>
                                                                                <div class="grid_18">
                                                                                    <p:outputLabel value="Laudo" styleClass="left"/>
                                                                                    <div class="clear"/>
                                                                                    <div class="grid_23">
                                                                                        <p:inputTextarea value="#{a.laudo}" />
                                                                                    </div> 
                                                                                </div> 
                                                                                <div class="clear"/>

                                                                            </ui:repeat>
                                                                        </div>
                                                                        <div class="clear"/>
                                                                        <hr/>
                                                                    </div>
                                                                </div>

                                                            </p:panel>
                                                        </div>
                                                    </ui:repeat>
                                                </p:panel>
                                                <br/>
                                            </p:tab>
                                        </p:tabView>
                                    </div>
                                </p:panel>
                            </fieldset>
                        </div>
                    </div>
                </div>
            </h:form>
            <h:form id="formDialog">
                <p:dialog id="dlgOperator"  widgetVar="dlgOperatorDialog"
                          header="Selecionar Convênio" modal="true"
                          width="800"  dynamic="true" > 

                    <p:messages autoUpdate="true" closable="true"/>

                    <p:panel id="operatorPanelSearch" style="background: none; border: none;" 
                             styleClass="container_24 clearfix ">


                        <p:dataTable var="opt" id="operatorDataTable" 
                                     value="#{managerAtendimento.operators}"  
                                     emptyMessage="Nenhum registro encontrado" 
                                     paginatorPosition="bottom" paginator="true" rows="10"
                                     rowKey="#{opt.id}" selection="#{managerAtendimento.operatorDiary}"
                                     selectionMode="single">
                            <p:ajax event="rowSelect"  
                                    onstart="dlgOperatorDialog.hide();"
                                    process="@this" 
                                    listener="#{managerAtendimento.loadIncome()}"
                                    update="@this, :diaryForm:tabView:panelatendimento, :diaryForm:tabView:fPanel"/>

                            <f:facet name="header">
                                Convênios
                            </f:facet> 
                            <p:ajax event="rowSelect"  process="@this" update="@this"/>
                            <p:ajax event="rowUnselect"  process="@this" update="@this"/>
                            <p:column  headerText="Descrição"  style="white-space: pre-wrap;"  >  
                                <h:outputText value="#{opt.name}" />  
                            </p:column>
                            <p:column  headerText="ANS" >  
                                <h:outputText value="#{opt.ans}" />  
                            </p:column>

                        </p:dataTable>
                    </p:panel>
                </p:dialog>
                <p:dialog id="dlgProcedure"  widgetVar="dlgProcedureDialog"
                          header="Pesquisar Procedimento" modal="true"
                          width="800"  dynamic="true" resizable="false"> 

                    <p:ajax event="close" update="@form, procedurePanelSearch" 
                            listener="#{managerDiary.initProcedure()}" /> 

                    <p:messages autoUpdate="true" closable="true"/>

                    <p:panel id="procedurePanelSearch" style="background: none; border: none;" 
                             styleClass="container_24 clearfix ">

                        <p:outputLabel value="Cód:" styleClass="grid_3"/>
                        <p:inputText styleClass="grid_3" value="#{managerAtendimento.procedureSearch.cod}"/>
                        <p:outputLabel value="Nome:" styleClass="grid_2"/>
                        <p:inputText styleClass="grid_14" value="#{managerAtendimento.procedureSearch.name}"/>
                        <div class="clear"/>
                        <div class="buttonAction">
                            <p:defaultCommand target="search-button-procedure" />
                            <p:commandButton id="search-button-procedure" value="Pesquisar" icon="ui-icon-search"
                                             update="procedurePanelSearch" process="procedurePanelSearch"
                                             actionListener="#{managerAtendimento.listProcedure()}"
                                             styleClass="ui-priority-primary" />
                        </div >

                        <p:dataTable id="tablePro" var="p" value="#{managerAtendimento.procedures}" 
                                     styleClass="grid_24"
                                     rowIndexVar="rowid"
                                     rowKey="#{p.id}"
                                     rows="5" paginator="true"  
                                     paginatorPosition="bottom"
                                     selectionMode="single"
                                     selection="#{managerAtendimento.procedure}"
                                     emptyMessage="Nenhum registro"> 

                            <p:ajax event="rowSelect"  
                                    oncomplete="dlgProcedureDialog.hide();"
                                    process="@this"
                                    listener="#{managerAtendimento.loadIncome()}"
                                    update="@this, :diaryForm:tabView:panelatendimento, :diaryForm:tabView:fPanel"/>

                            <f:facet name="header">
                                Procedimentos
                            </f:facet>
                            <p:column headerText="Cod">  
                                <h:outputText value="#{p.cod}"/>
                            </p:column>  
                            <p:column headerText="Nome">  
                                <h:outputText value="#{p.name}"/>
                            </p:column>
                            <p:column headerText="Duração">  
                                <h:outputText value="#{p.duration}"/>
                            </p:column>
                        </p:dataTable> 
                    </p:panel>
                </p:dialog>
                <p:dialog id="dlgDoctorRequest"  widgetVar="dlgDoctorRequestDialog"
                          header="Pesquisar Médico" modal="true"
                          width="800"  dynamic="true" > 

                    <p:messages autoUpdate="true" closable="true"/>

                    <p:panel id="medicoRequestPanelSearch" style="background: none; border: none;" 
                             styleClass="container_24 clearfix ">

                        <p:outputLabel value="Nome:" styleClass="grid_3"/>
                        <p:inputText styleClass="grid_20" value="#{managerAtendimento.doctorPesquisar.name}"/>

                        <div class="buttonAction">
                            <p:defaultCommand target="search-button-medicorequest" />
                            <p:commandButton id="search-button-medicorequest" value="Pesquisar" icon="ui-icon-search"
                                             update="medicoRequestPanelSearch" process="medicoRequestPanelSearch"
                                             actionListener="#{managerAtendimento.listDoctor()}"
                                             styleClass="ui-priority-primary" />
                        </div >

                        <p:dataTable var="dct" id="doctorRequestDataTable" value="#{managerAtendimento.doctors}"  
                                     selectionMode="single" rowKey="#{dct.id}"
                                     selection="#{managerAtendimento.doctorRequest}"
                                     emptyMessage="Nenhum registro encontrado" sortMode="multiple"
                                     paginatorPosition="bottom" paginator="true" rows="5">
                            <p:ajax event="rowSelect"  
                                    onstart="dlgDoctorRequestDialog.hide();"
                                    process="@this" 
                                    update="@this, :diaryForm:tabView:panelatendimento"/>
                            <f:facet name="header">
                                Médicos
                            </f:facet> 
                            <p:ajax event="rowSelect"  process="@this" update="@this"/>
                            <p:ajax event="rowUnselect"  process="@this" update="@this"/>
                            <p:column  headerText="Nome"  style="white-space: pre-wrap;" >  
                                <h:outputText value="#{dct.name}" />  
                            </p:column>
                            <p:column  headerText="CBO" width="150" >  
                                <h:outputText value="#{dct.cbo.descr}" />  
                            </p:column>


                        </p:dataTable>

                    </p:panel>
                </p:dialog>

                <p:dialog id="dlgDoctor"  widgetVar="dlgDoctorDialog"
                          header="Pesquisar Médico" modal="true"
                          width="800"  dynamic="true" > 

                    <p:messages autoUpdate="true" closable="true"/>

                    <p:panel id="medicoPanelSearch" style="background: none; border: none;" 
                             styleClass="container_24 clearfix ">

                        <p:outputLabel value="Nome:" styleClass="grid_3"/>
                        <p:inputText styleClass="grid_20" value="#{managerAtendimento.doctorPesquisar.name}"/>

                        <div class="buttonAction">
                            <p:defaultCommand target="search-button-medico" />
                            <p:commandButton id="search-button-medico" value="Pesquisar" icon="ui-icon-search"
                                             update="medicoPanelSearch" process="medicoPanelSearch"
                                             actionListener="#{managerAtendimento.listDoctor()}"
                                             styleClass="ui-priority-primary" />
                        </div >

                        <p:dataTable var="dct" id="doctorDataTable" value="#{managerAtendimento.doctors}"  
                                     selectionMode="single" rowKey="#{dct.id}"
                                     selection="#{managerAtendimento.doctor}"
                                     emptyMessage="Nenhum registro encontrado" sortMode="multiple"
                                     paginatorPosition="bottom" paginator="true" rows="5">

                            <p:ajax event="rowSelect"  
                                    onstart="dlgDoctorDialog.hide();"
                                    oncomplete="myschedule.update();"
                                    process="@this" 
                                    listener="#{managerAtendimento.initSchedule()}"
                                    update="@this, :diaryForm:tabView:panelatendimento"/>


                            <f:facet name="header">
                                Médicos
                            </f:facet> 

                            <p:column  headerText="Nome" >  
                                <h:outputText value="#{dct.name}" />  
                            </p:column>

                            <p:column  headerText="CBO"  style="white-space: pre-wrap;" width="150">  
                                <h:outputText value="#{dct.cbo.descr}" />  
                            </p:column>

                        </p:dataTable>
                    </p:panel>
                </p:dialog>
                <p:dialog  widgetVar="fImprimir" header="Imprimir Folha de Rosto" modal="true"
                           width="800" showEffect="clip" resizable="false" >

                    <p:ajax event="close" listener="#{managerDiary.cleanPrint()}" update="fPanelImprimir" /> 

                    <p:panel id="fPanelImprimir" style="background: none; border: none;" styleClass="container_24 clearfix " >
                        <p:dataTable id="diarysPrint" var="print" paginator="true" rows="10"
                                     paginatorPosition="bottom"
                                     value="#{managerAtendimento.diarysDisp}"
                                     rowKey="#{print.id}" selection="#{managerAtendimento.diarysSelected}" 
                                     selectionMode="multiple">

                            <p:ajax event="rowSelect"  process="@this" update="@this"/>
                            <p:ajax event="rowUnselect"  process="@this" update="@this"/>

                            <p:column headerText="Data">  
                                <h:outputText value="#{print.startTime}" >  
                                    <f:convertDateTime pattern="dd/MM/yyyy à's' HH:mm:ss"/>
                                </h:outputText>
                            </p:column>  

                            <p:column headerText="Situação" style="white-space: pre-wrap;" >  
                                <h:outputText value="#{print.diarySituation.toString()}" />  
                            </p:column>  

                            <p:column headerText="Procedimento" style="white-space: pre-wrap;">  
                                <h:outputText value="#{print.retorno ? 'Retorno - ':''}#{print.procedure.name}" />  
                            </p:column>  

                            <p:column headerText="Paciente" style="white-space: pre-wrap;">  
                                <h:outputText value="#{print.customer.name}" />  
                            </p:column>


                        </p:dataTable>


                    </p:panel>
                    <f:facet name="footer" >
                        <div class="grid_24 right">
                            <p:commandButton 
                                value="Imprimir" icon="ui-icon-print" immediate="true"
                                ajax="false"  onclick="this.form.target='_blank'"
                                styleClass="right" action="#{managerAtendimento.diaryReport()}"/>
                        </div>
                    </f:facet>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
